package com.qf.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.pojo.DtsOrder;
import com.qf.vo.CategorySellAmts;
import com.qf.vo.DayStatis;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 订单表 Mapper 接口
 * </p>
 *
 * @author zhaojian
 * @since 2021-05-12
 */
public interface DtsOrderMapper extends BaseMapper<DtsOrder> {

    /**
     * 统计最近多少天内的订单的增长量和当天订单的总金额
     * @return
     */
    @Select("SELECT\n" +
            "DATE_FORMAT(a.add_time,\"%Y-%m-%d\") as dayStr,\n" +
            "count(*) as cnts,\n" +
            "sum(actual_price) as amts\n" +
            "FROM\n" +
            "\tdts_order a \n" +
            "WHERE\n" +
            "\ta.deleted = 0 \n" +
            "group by DATE_FORMAT(a.add_time, \"%Y-%m-%d\")")
    public List<DayStatis> staticsIncresOrderCnt();


    /**
     * 按照分类，统计每个分类中商品的销售额
     * @return
     */
    @Select("SELECT\n" +
            "\td.`name`,sum(a.price) as value\n" +
            "FROM\n" +
            "\tdts_order_goods a\n" +
            "\tLEFT JOIN dts_order b ON a.order_id = b.id\n" +
            "\tLEFT JOIN dts_goods c ON a.goods_id = c.id\n" +
            "\tLEFT JOIN dts_category d ON c.category_id = d.id\n" +
            "\twhere a.deleted=0 and b.deleted=0 and d.name is not null\n" +
            "\tgroup by d.name")
    public List<CategorySellAmts> categorySell();

}
